
function factory (UserModel) {
  return function (req, res) {
    var body = req.body;
    if (body.authCode !== req.session.authCode) {
      res.send('-1')
    }else {
      UserModel.findOne({user: body.user}, function (err, user) {
        if (!user) {
          UserModel.findOne({email: body.email}, function (err, user) {
             if (!user) {
              var user =new UserModel({
                user: body.user,
                password: body.password,
                email: body.email,
                sex: body.sex
              })
              user.save(function (err, user) {
                res.send('1')
              })
            }else {
              res.send('3')
            }
          })
          
        }else {
          res.send('0')
        }
      })
    }
  }
}

module.exports = factory
